package com.wenwei.paper.activity;

import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.wenwei.paper.R;
import com.wenwei.paper.adapter.ReplenishmentAdapter;
import com.wenwei.paper.base.BaseActivity;
import com.wenwei.paper.bean.AddGoodsListBean;
import com.wenwei.paper.net.ApiManager;
import com.wenwei.paper.net.BaseSubscriber;
import com.wenwei.paper.view.AddPopupWindow;

import java.util.ArrayList;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2017/7/13.
 */
public class ReplenishmentActivity extends BaseActivity {
    @Bind(R.id.base_title)
    TextView baseTitle;
    @Bind(R.id.recycler)
    RecyclerView recycler;
    @Bind(R.id.content_ll)
    LinearLayout contentLl;

    ReplenishmentAdapter mAdapter;

    private String deviceId;

    @Override
    protected void init() {
        super.init();
        deviceId = getIntent().getStringExtra("deviceId");
    }

    @Override
    public int setLayoutResourceId() {
        return R.layout.activity_replenishment;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @Override
    protected void initView() {
        super.initView();
        baseTitle.setText("补货");
        recycler.setLayoutManager(new GridLayoutManager(mContext,3));
        mAdapter = new ReplenishmentAdapter(new ReplenishmentAdapter.CallBack() {
            @Override
            public void onItemClick(int devicelistId,int num) {
                new AddPopupWindow(ReplenishmentActivity.this, devicelistId,num,contentLl, new AddPopupWindow.CallBack() {
                    @Override
                    public void onCommitOk() {
                        showToast("补货成功");
                    }
                });
            }
        });
        recycler.setAdapter(mAdapter);
    }

    @OnClick(R.id.base_back)
    public void onViewClicked() {
        finish();
    }

    @Override
    protected void initData() {
        super.initData();
        getAddGoodsList();
    }

    private BaseSubscriber<ArrayList<AddGoodsListBean>> goodsSubscriber;
    private void getAddGoodsList(){
        goodsSubscriber = new BaseSubscriber<ArrayList<AddGoodsListBean>>(mContext) {
            @Override
            public void onSuccess(ArrayList<AddGoodsListBean> addGoodsListBeen) {
                mAdapter.setDataList(addGoodsListBeen);
                mAdapter.notifyDataSetChanged();
            }
        };
        ApiManager.getInstance().getAddGoodsList(goodsSubscriber,deviceId);
    }
}
